﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace OntologyFormDesigner.Widget
{
    public class WidgetPanel : Panel, OntologyUtility.Interfaces.IWidget
    {
        protected OntologyUtility.Xml.Appearance apperance;
        public OntologyUtility.Xml.Appearance Appearance
        {
            get
            {
                if (apperance == null)
                {
                    String backColor = this.BackColor.R + "," + this.BackColor.G + "," + this.BackColor.B;
                    String foreColor = this.ForeColor.R + "," + this.ForeColor.G + "," + this.ForeColor.B;
                    String cursor = this.Cursor.ToString();
                    return new OntologyUtility.Xml.Appearance(backColor, foreColor, cursor);
                }
                return apperance;
            }
            set
            {
                try
                {
                    apperance = value;
                    this.BackColor = UIUtil.GetColorByRGB(apperance.BackColor);
                    this.ForeColor = UIUtil.GetColorByRGB(apperance.ForeColor);
                }
                catch (Exception)
                {
                    
                }
            }
        }

        protected String type = null;
        public string Type
        {
            get
            {
                try
                {
                    return type == null ? this.GetType().Name : type;
                }
                catch (Exception)
                {
                    return "";
                }
            }
            set
            {
                type = value;
            }
        }

        protected OntologyUtility.Xml.WidgetFont font = null;
        public OntologyUtility.Xml.WidgetFont WidgetFont
        {
            get
            {
                return font == null ? new OntologyUtility.Xml.WidgetFont(this.Font.Name, this.Font.Size.ToString(), this.Font.Style.ToString()) : font;
            }
            set
            {
                try
                {
                    this.font = value;
                    this.Font = new System.Drawing.Font(
                        WidgetFont.Name,
                        float.Parse(WidgetFont.Size),
                        (FontStyle)Enum.Parse(typeof(FontStyle), font.Style)
                    );
                }
                catch (Exception)
                {
                   
                }
            }
        }

        protected OntologyUtility.Xml.WidgetLocation location = null;
        public OntologyUtility.Xml.WidgetLocation WidgetLocation
        {
            get
            {
                return location == null ? new OntologyUtility.Xml.WidgetLocation(this.Location.X, this.Location.Y, this.Dock.ToString(), this.Anchor.ToString()) : location;
            }
            set
            {
                try
                {
                    this.location = value;
                    this.Left = location.X;
                    this.Top = location.Y;
                    this.Dock = UIUtil.DockStyleByString(location.Dock);
                    this.Anchor = UIUtil.AnchorStyleByString(location.Anchor);
                }
                catch (Exception)
                {
                   
                }
            }
        }

        protected String wParent = null;
        public String WidgetParent
        {
            get
            {
                try
                {
                    return wParent == null ? this.Parent.Name : wParent;
                }
                catch (Exception)
                {
                    return "";
                }
            }
            set
            {
                wParent = value;
            }
        }

        protected OntologyUtility.Xml.WidgetSize wSize = null;
        public OntologyUtility.Xml.WidgetSize WidgetSize
        {
            get
            {
                return wSize == null ? new OntologyUtility.Xml.WidgetSize(this.Width, this.Height) : wSize;
            }
            set
            {
                try
                {
                    wSize = value;
                    this.Size = new Size(wSize.Width, wSize.Height);
                }
                catch (Exception)
                {
                   
                }
            }
        }
    }
}
